package com.tju.t5.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;


public class AuthorityInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public AuthorityInterceptor() {
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		ActionContext context = invocation.getInvocationContext();
		@SuppressWarnings("rawtypes")
		Map session = context.getSession();
		
		String user = (String)session.get("username");
		if(user != null)
		{
			return invocation.invoke();
		}
		else
		{
			session.clear();
			return Action.LOGIN;
		}
	}

}
